import { IState } from "../typings";
import { SET_PHONE_LIST } from "./actionTypes";
import { TAction} from './actions';
import initialState from './state';

/**
 * @description 该函数根据type的值去修改state数据，必须初始化state数据
 * @param state 初始化的state数据
 * @param action action对象
 * @returns 必须返回一个新的state对象去覆盖原有的state数据
 */
function reducers(state: IState = initialState, action: TAction): IState {
  switch (action.type) {
    case SET_PHONE_LIST:
      return {
        //平铺原来state里所有的属性
        ...state,
        //修改phoneList属性数据
        phoneList: action.payload
      };
    default:
      //默认不做操作返回一个state对象
      return state;
  }
}

export default reducers;